# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'console.ui'
#
# Created: Wed Feb 29 18:20:28 2012
#      by: PyQt4 UI code generator 4.9
#
# WARNING! All changes made in this file will be lost!
import sys
sys.path.append('/archivos/source/sql_rice')


from PyQt4 import QtCore, QtGui
from tools.ruledit import RuleEditor

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s


class Ui_ConsoleWidget(object):

    def setupUi(self, ConsoleWidget):
        ConsoleWidget.setObjectName(_fromUtf8("ConsoleWidget"))
        ConsoleWidget.resize(435, 402)
        ConsoleWidget.setMinimumSize(QtCore.QSize(142, 300))
        self.dockWidgetContents = QtGui.QWidget()
        self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents"))
        self.verticalLayout = QtGui.QVBoxLayout(self.dockWidgetContents)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.textEdit = QtGui.QTextEdit(self.dockWidgetContents)
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.verticalLayout.addWidget(self.textEdit)
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.lineEdit = QtGui.QLineEdit(self.dockWidgetContents)
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.horizontalLayout.addWidget(self.lineEdit)
        self.pushButton = QtGui.QPushButton(self.dockWidgetContents)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.horizontalLayout.addWidget(self.pushButton)
        self.verticalLayout.addLayout(self.horizontalLayout)
        ConsoleWidget.setWidget(self.dockWidgetContents)

        self.retranslateUi(ConsoleWidget)
        QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(
            _fromUtf8("returnPressed()")), ConsoleWidget.execute)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(
            _fromUtf8("clicked()")), ConsoleWidget.execute)
        QtCore.QMetaObject.connectSlotsByName(ConsoleWidget)

    def retranslateUi(self, ConsoleWidget):
        ConsoleWidget.setWindowTitle(QtGui.QApplication.translate(
            "ConsoleWidget", "Console", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate(
            "ConsoleWidget", "Execute", None, QtGui.QApplication.UnicodeUTF8))


class TextEditWriter(object):

    def __init__(self, qtext_edit):
        self.edit = qtext_edit

    def write(self, value):
        self.edit.append(str(value))


class ConsoleWidget(QtGui.QDockWidget):

    def __init__(self, parent=None):
        QtGui.QDockWidget.__init__(self)
        self._ui = Ui_ConsoleWidget()

    def show(self):
        self._ui.setupUi(self)
        self._command = RuleEditor(stdout=TextEditWriter(self._ui.textEdit))
        QtGui.QDockWidget.show(self)

    def execute(self):
        self._command.onecmd(str(self._ui.lineEdit.text()))

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    console = ConsoleWidget()
    console.show()
    sys.exit(app.exec_())
